﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;

namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Settings Repository
    /// </summary>
    public class SettingsRepository:ISettingsRepository
    {
    }

    /// <summary>
    /// Company Information Repository
    /// </summary>
    public class CompanyInfoRepository : ICompanyInfoRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Company Info by Company Name
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<CompanyInfo> FindCompanyInfoByName(string strQuery)
        {
            return _db.CompanyInfos.Where(d => d.CompanyName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Company Infos
        /// </summary>
        /// <returns></returns>
        public IQueryable<CompanyInfo> FindAllCompanyInfo()
        {
            return _db.CompanyInfos;
        }

        /// <summary>
        /// Get Company Info by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CompanyInfo GetCompanyInfoById(int id)
        {
            return _db.CompanyInfos.SingleOrDefault(d => d.CompanyId == id);
        }

        /// <summary>
        /// Add Company Info in the Database
        /// </summary>
        /// <param name="companyInfo"></param>
        public void Add(CompanyInfo companyInfo)
        {
            _db.CompanyInfos.AddObject(companyInfo);
        }

        /// <summary>
        /// Delete Template from Database
        /// </summary>
        /// <param name="companyInfo"></param>
        public void Delete(CompanyInfo companyInfo)
        {
            _db.CompanyInfos.DeleteObject(companyInfo);
        }

        /// <summary>
        /// Save Company Info in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}